angular.module('Controller')

.controller('QgyFloorPlansManageCtrl', ($scope,NgTableParams,menuManage,commonUtil,commonConstant,$rootScope,$uibModal,$http) ->
    ##状态：0-未激活，1-正常，2-已出租，3-不可用
    $scope.roomActiveStatusList=commonConstant.roomActiveStatusList()
    $scope.projectList=[
        {id:undefined ,name:'未选择'}
        {id:1,name:'项目一'},
        {id:2,name:'项目二'},
        {id:3,name:'项目三'},
        {id:4,name:'项目四'},
        {id:5,name:'项目五'}
    ]
    $scope.unitList=[
        {id:undefined ,name:'未选择'}
        {id:1,name:'7号楼'},
        {id:2,name:'8号楼'},
        {id:3,name:'12号楼'},
        {id:4,name:'13号楼'},
        {id:5,name:'14号楼'},
        {id:6,name:'26号楼'}
    ]
    $scope.unitFlourList=[
        {id:undefined ,name:'未选择'}
        {id:1,name:'一楼'},
        {id:2,name:'二楼'},
        {id:3,name:'三楼'},
        {id:4,name:'四楼'},
        {id:5,name:'七楼'},
        {id:6,name:'八楼'},
        {id:7,name:'十二楼'},
        {id:8,name:'十四楼'}
    ]
    roomList=[
        {id:1,name:'房间一',width:48,height:76,top:50,left:66,rotate:0,status:2},
        {id:2,name:'房间二',width:48,height:76,top:50,left:116,rotate:0,status:1},
        {id:3,name:'房间三',width:48,height:76,top:50,left:166,rotate:0,status:1},
        {id:4,name:'房间四',width:48,height:76,top:50,left:216,rotate:0,status:2},
        {id:5,name:'房间五',width:48,height:76,top:50,left:266,rotate:0,status:3}
    ]
    initData=()->
        $scope.data={
            project:undefined,
            unit:undefined ,
            floor:undefined ,
        }
        $scope.floorInfo=undefined
        $scope.info={
            newRoomNum:5
        }
        ''
    initData()
    _.extend $scope,
        pickRoom:(id)->
            console.log('pickRoom',id)
            if id!=undefined
                $scope.roomInfo=_.find $scope.floorInfo.roomList,(room)->room.id==id
            else
                $scope.roomInfo=undefined
        doMaintain:()->
            $scope.floorInfo={
                name:'南桥社区15号楼7层'
                planUrl:'images/floor-plan1.png'
                roomNum:5
                roomList:roomList
                currentRoom:undefined
                editingRoomNum:false
            }
            if $scope.floorInfo.roomList?.length>0
                $scope.floorInfo.currentRoom=$scope.floorInfo.roomList[0].id
                $scope.pickRoom($scope.floorInfo.currentRoom)
        roomStyle:(item)->
            style={
                "width" : item.width+'px',
                "height" : item.height+'px',
                "line-height":item.height+'px',
                "left" : item.left+'px',
                "top" : item.top+'px',
                "border":if item.id==$scope.roomInfo.id then '2px solid yellowgreen' else 'none'
            }
            return style
        checkNewRoomNum:()->
            newNum=parseInt($scope.info.newRoomNum)
            if newNum+''==$scope.info.newRoomNum && newNum>0 && newNum<256
                return false
            else
                return true
        editRoomNum:()->
            $scope.info.newRoomNum=$scope.floorInfo.roomNum
            $scope.floorInfo.editingRoomNum=true
        saveRoomNum:()->
            $scope.floorInfo.roomNum=$scope.info.newRoomNum
            $scope.floorInfo.editingRoomNum=false
)
